package com.iptv.grape.event.imp;

import android.view.View;

import com.google.gson.Gson;
import com.iptv.grape.BaseActivity;
import com.iptv.grape.bu.GrapeContext;
import com.iptv.grape.domain.UserInfo;
import com.iptv.grape.event.EventArgs;
import com.iptv.grape.event.JSRequest;
import com.iptv.grape.event.LiveWindowDataArgs;
import com.iptv.grape.event.proc.IWebViewMessageProc;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.util.CommUtil;
import com.iptv.grape.video.VideoSize;
import com.iptv.grape.video.XMediaPlayer;

import org.greenrobot.eventbus.EventBus;

// 创建直播小窗口
public class LiveWindow implements IWebViewMessageProc {

    private LiveWindowDataArgs argsData;
    @Override
    public void init(JSRequest jsRequest) {
        try {
            argsData = new Gson().fromJson(jsRequest.getJson(), LiveWindowDataArgs.class);
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public String procMessage(BaseActivity baseActivity, XMediaPlayer mediaPlayer) {
        if(argsData != null){
            // 根据参数来请求初始化直播小窗口
            //EventBus.getDefault().post(new EventArgs("InitLiveWindow", "JsEvent",argsData));
            // 开始初始化小窗口
            AppLog.getCurLog().out("MainActivity---------开始初始化直播小窗口");


            VideoSize videoSize = CommUtil.getVideoSize(baseActivity,argsData);
            if(GrapeContext.curGrapeContext().getLastPlayChannel()!=null) {
                mediaPlayer.play(baseActivity,
                        GrapeContext.curGrapeContext().getLastPlayChannel(),
                        videoSize);
                GrapeContext.curGrapeContext().setPlaying(true);
                GrapeContext.curGrapeContext().setCurPlayType("Live");
                GrapeContext.curGrapeContext().setCurLiveType("Live");
            }
        }
        return "";
    }



}
